"""
# -*- coding: utf-8 -*-
Time    : 2025/7/24 上午11:23
Author  : Micah
File    : test_db_transact.py
Function:
"""

import pytest


class DB:
    def __init__(self):
        self.transaction = []

    def begin(self, name):
        self.transaction.append(name)

    def rollback(self):
        self.transaction.pop()


@pytest.fixture(scope="module")
def db():
    return DB()


class TestClass:
    @pytest.fixture(autouse=True)
    def transact(self, request, db):
        db.begin(request.function.name)
        yield
        db.rollback()

    def test_method1(self, db):
        assert db.transaction == "test_method1"

    def test_method2(self, db):
        assert db.transaction == "test_method2"

